package org.phantom.demo.picture;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;

import org.phantom.demo.api.SearchBean;
import org.phantom.demo.api.SearchHandler;
import org.phantom.demo.api.SearchParameter;
import org.springframework.stereotype.Service;

@Service
public class PictureSearchHandler implements SearchHandler{

	
	private List<Picture> pictures = null;
	
	@PostConstruct
	public void init(){
		pictures = new ArrayList<Picture>();
		pictures.add(new Picture("aaaa","aaaa"));
		pictures.add(new Picture("bbbb","bbbb"));
		pictures.add(new Picture("cccc","cccc"));
		pictures.add(new Picture("dddd","dddd"));
		pictures.add(new Picture("eeee","eeee"));
	}
	
	@Override
	public List<? extends SearchBean> doSearch(SearchParameter parameter) {
		String key = parameter.getSearchValue().toString();
		List<Picture> temp = new ArrayList<Picture>();
		for (Picture p : this.pictures) {
			if(p.getDesc().startsWith(key))
				temp.add(p);
		}
		return temp;
	}
	
}